package com.heima.crm.controller;

import com.heima.crm.common.result.PageResult;
import com.heima.crm.common.result.Result;
import com.heima.crm.pojos.dtos.DicDataPageDTO;
import com.heima.crm.pojos.dtos.DicTypePageDTO;
import com.heima.crm.pojos.entity.SysDictData;
import com.heima.crm.service.SysDicDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/dicData")
public class SysDicDataController {
    @Autowired
    private SysDicDataService sysDicDataService;

    //字典下拉框
    @PostMapping("/getLabel/{dictType}")
    public Result getDicData(@PathVariable String dictType){
        return sysDicDataService.getDicData(dictType);
    }

    //分页查询字典(名称,类型,状态,创建时间)
    @PostMapping("/list")
    public PageResult findList(@RequestBody DicDataPageDTO dto){
        return sysDicDataService.findList(dto);
    }

    @PostMapping("/add")
    public Result add(@RequestBody SysDictData sysDictData){
        return sysDicDataService.add(sysDictData);
    }

    @GetMapping("/findOne/{dictCode}")
    public Result findById(@PathVariable Long dictCode){
        return sysDicDataService.findById(dictCode);
    }

    @PutMapping("/update")
    public Result update(@RequestBody SysDictData sysDictData){
        return sysDicDataService.update(sysDictData);
    }

    @DeleteMapping("/delete/{dictCode}")
    public Result deleteById(@PathVariable Long dictCode){
        return sysDicDataService.deleteById(dictCode);
    }

    @DeleteMapping("/deleteIds")
    public Result deleteByIds(@RequestParam List<Long> ids){
        return sysDicDataService.deleteByIds(ids);
    }

    @PostMapping("/export")
    public Result export(HttpServletResponse response,@RequestParam List<Long> ids){
        return sysDicDataService.export(response,ids);
    }

    //测试
    @PostMapping("/addType")
    public void addType(){
        sysDicDataService.addType();
    }
}
